{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit" ng-app="hd" ng-controller="ctrl">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form layui-form-pane"> 
        <div class="layui-form-item">
            <label class="layui-form-label">通道名称</label>
            <div class="layui-input-4">
                <input type="text" name="title" ng-model="field.title" lay-verify="required" class="layui-input">
            </div>
        </div>  
        <div class="layui-form-item">
            <label class="layui-form-label">所属商户</label>
            <div class="layui-input-4">
                <select name="shopid" id="shopid" lay-verify="required" lay-filter="shopid"  ng-model="field.shopid" ng-options="v.id as v.name for v in shoplist" ng-selected="v.id==field.shopid">
                    <option value="">请选择商户</option>
                </select>
            </div> 
            <input type="text" name="shopname" id="shopname" ng-model="field.shopname" lay-verify="required" class="layui-input layui-hide">
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属币种</label>
            <div class="layui-input-4">
                <select name="cionid" id="cionid" lay-filter="cionid"  lay-verify="required" ng-model="field.cionid" ng-options="v.id as v.name for v in cionlist" ng-selected="v.id==field.cionid">
                    <option value="">请选择币种</option>
                </select>
            </div>
            <input type="text" name="cionname" id="cionname" ng-model="field.cionname" lay-verify="required" class="layui-input layui-hide">
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单价</label>
            <div class="layui-input-4">
                <input type="text" name="price" ng-model="field.price" lay-verify="number" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux"><span class="red">如特别要求，请勿修改此项。当币单价发生变化时，此项会同步</span></div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label">通道手续费</label>
            <div class="layui-input-4">
                <input type="text" name="rate" ng-model="field.rate" lay-verify="required" placeholder="{:lang('pleaseEnter')}手续费" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux"><span class="red">%（即*0.01）码商通道手续费率需小于（<）等于商户手续费</span></div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label">是否审核</label>
            <div class="layui-input-block">
                <input type="radio" name="open" ng-model="field.open" ng-checked="field.open==1" ng-value="1" title="{:lang('open')}">
                <input type="radio" name="open" ng-model="field.open" ng-checked="field.open==0" ng-value="0" title="{:lang('close')}">
            </div>
        </div>  
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script src="/static/common/js/angular.min.js"></script>
<script>  
    var m = angular.module('hd',[]);
    m.controller('ctrl',['$scope',function($scope) {
        $scope.field = '{$info|raw}'!='null'?{$info|raw}:{id:'',title:'',open:1};
        $scope.shoplist = {$shoplist|raw}; 
        $scope.cionlist = {$cionlist|raw};  
        layui.use(['form', 'layer'], function () { 
            var form = layui.form, layer = layui.layer,$= layui.jquery; 
            form.on('select(shopid)', function(data){ 
                var name=$("#shopid option:checked").text(); 
                $('#shopname').val(name);   
                var shopid =data.value.slice(7); 

                console.log(shopid);
                $.get("{:url('shop/getCion')}?shopid=" + shopid, function (data) {
                    var html = '<option value="">请选择币种</option>';
                    $.each(data, function (i, value) {
                        html += '<option value="' + value.id + '">' + value.name + '/'+value.name_en+'</option>';
                    });
                    $('#cionid').html(html); 
                    form.render()
                });
            });  
            form.on('select(cionid)', function(data){
                var name=$("#cionid option:checked").text(); 
                $('#cionname').val(name);  
            });  
            form.on('submit(submit)', function (data) {
                // 提交到方法 默认为本身
                data.field.id = $scope.field.id;
                data.field.userid = $scope.field.userid; 
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("", data.field, function (res) {
                    layer.close(loading);
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            });
        });
    }]);
</script>